﻿using B.S.Data.MES.API.Applications.QualityManagement.ExamineTaskCommand.Commands;
using B.S.Domain.BasicData.QualityManagement;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.QualityManagement.ExamineTaskCommand.CommandHandlers
{
    public class DeleteExamineTaskCommandHandler : IRequestHandler<DeleteExamineTaskCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<ExamineTask> _examinetaskRepository;
        public DeleteExamineTaskCommandHandler(IBaseRepository<ExamineTask> examinetaskRepository)
        {
            _examinetaskRepository = examinetaskRepository;

        }
        public Task<APIRequst<int>> Handle(DeleteExamineTaskCommand request, CancellationToken cancellationToken)
        {
            APIRequst<int> result = new APIRequst<int>();
            result.Code = RequstCode.成功;
            result.Msg = RequstCode.成功.ToString();
            var ment = _examinetaskRepository.GetAll().FirstOrDefault(x => x.TaskId == request.taskId);

            ment.isDel = true;
            ment.DeleteName = request.DeleteName;
            ment.DeleteTime = DateTime.Now;

            _examinetaskRepository.Update(ment);
            return Task.FromResult(result);

        }
    }
}
